package com.chat.adapter;

import java.util.ArrayList;
import java.util.Collections;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.contact.ADData;
import com.contact.ObjTool;
import com.util.AppUtil;

public class JSONUtil {
	/**
	 * 
	 * @Description: 解析栏目列表
	 * @param jsonStr
	 * @return
	 * @throws JSONException
	 */
	public static ArrayList<ADData> parseAdList(JSONArray ja)
			throws JSONException {
		ArrayList<ADData> list = null;
		if (ja != null && ja.length() > 0) {
			list = new ArrayList<ADData>();
			for (int i = 0; i < ja.length(); i++) {
			JSONObject jo=ja.getJSONObject(i);
			String url = jo.optString("vediourl");
			if(AppUtil.isLegalVideo(url)){
				ADData d=new ADData();
				d.id=jo.optString("id");
				d.title=jo.optString("title");
				d.videoUrl=jo.optString("vediourl");
				d.howlong=jo.optInt("howlong");
				d.startTime=jo.optString("starttime");
			  //  d.timeStampStart=TimeTool.genTimestampFromStr(d.startTime);
			    d.timeStampEnd=d.timeStampStart+59*60*1000;
//			    d.timeStampEnd=d.timeStampStart+d.howlong*1000;
			    list.add(d);
			}else{
				continue;
			}
			
			}
		}
		/**
		 * 排序
		 */
		if(ObjTool.isNotNull(list)){
			Collections.sort(list);
		}
		
		return list;
	}
}
